#lang sicp
(define (make-accumulator sum)
  (lambda (numeric)
    (set! sum (+ sum numeric))
    sum))

(define A (make-accumulator 100))

(define (make-monitored f)
  (let ((count 0))
    (define (mf m)
      (cond ((eq? m 'how-many-calls?) count)
            ((eq? m 'reset-count) (set! count 0) count)
            (else
             (set! count (+ 1 count))
             (f m))))
    mf))

(define s (make-monitored sqrt))


(define (make-account balance password)
  (define (deposit amount)
    (set! balance (+ balance amount))
    balance)
  (define (withdraw amount)
    (if (> amount balance)
        "insufficient funds"
        (begin (set! balance (- balance amount))
               balance)))
  (define (dispatch m)
    (cond ((eq? m 'deposit) deposit)
          ((eq? m 'withdraw) withdraw)
          (else (error "Unknow request: MAKE-ACCOUNT" m))))
  (let ((consecutive-incorrect-time 0))
    (define (request msg pwd)
      (if (eq? pwd password)
          (begin (set! consecutive-incorrect-time 0)
                 (dispatch msg))
          (begin
            (set! consecutive-incorrect-time (+ 1 consecutive-incorrect-time))
            (if (> consecutive-incorrect-time 7)
                (call-the-cops))
            (lambda (v) "Incorrect password"))))
    request))

(define (call-the-cops) (display "but don't care -- CALL-THE-COPS"))

(define acc (make-account 100 'secret-password))